package com.hejjon.controller;

import com.hejjon.core.bean.ResponseResult;
import com.hejjon.core.bean.StrListBean;
import com.hejjon.core.controller.BaseController;
import com.hejjon.core.domain.entity.SysMenu;
import com.hejjon.core.domain.vo.MenuVO;
import com.hejjon.service.ISysMenuService;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * 系统菜单前端控制器
 * @author: cs
 * @date: 2024-12-19 22:28:58
 * @since: 1.0
 */
@RestController
@RequestMapping("/system/menu")
public class SysMenuController extends BaseController {


    @Resource
    private ISysMenuService sysMenuService;

    @GetMapping("/getTopMenus")
    public ResponseResult getTopMenus() {
        List<MenuVO> menus = sysMenuService.findTopNavMenuList();
        return success(menus);
    }


    @PostMapping("/add")
    public ResponseResult add(@RequestBody SysMenu menu) {
        boolean unique = sysMenuService.checkNameAndTextUnique(menu.getName(), menu.getText());
        if (!unique) {
            return warn("菜单名称重复!");
        }
        return toResult(sysMenuService.add(menu));
    }


    @GetMapping("/getSubMenusByParentId")
    public ResponseResult getSubMenusByParentId(@RequestParam("parentId") String parentId) {
        return success(sysMenuService.findSubMenusByParentId(parentId));
    }


    @GetMapping("/getMenuData")
    public ResponseResult getMenuData() {
        return success(sysMenuService.getMunuData());
    }


    @GetMapping("/getMenuVoList")
    public ResponseResult getMenuVoList(@RequestParam("searchParam") String searchParam) {
        return success(sysMenuService.getMenuVoList(searchParam));
    }


    /**
     * 批量删除
     * @param req
     * @return
     */
    @PostMapping("/batchRemove")
    public ResponseResult batchRemove(@RequestBody StrListBean req) {

        return toResult(sysMenuService.removeByIds(req.getIds()), "菜单删除成功!");
    }

}
